﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>通用数据维护</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/Content/X-admin/lib/layui/layui.js"></script>
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/Common.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>

</head>
<body>
    <span style="margin-top:15px;margin-left:15px">
        <xblock>
            <button class="layui-btn" onclick="saveData()"><i class="layui-icon"></i>保存</button>
            <button class="layui-btn" onclick="closeWin()"><i class="layui-icon">&#x1006;</i>取消</button>
        </xblock>
    </span>
    <div style="margin: 10px; border: 1px solid #dbdbdb;padding:15px">

        <form id="AddForm" class="layui-form layui-col-space5">
            <div class="layui-form-item">
                <label class="layui-form-label">编号</label>
                <div class="layui-input-inline">
                    <input type="text" name="cCode" lay-verify="required" autocomplete="off" class="layui-input" id="cCode">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="cName" lay-verify="required" autocomplete="off" class="layui-input" id="cName">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">属性值</label>
                <div class="layui-input-inline">
                    <input type="text" name="cMemo" autocomplete="off" class="layui-input" id="cMemo" />

                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">节点编码</label>
                <div class="layui-input-inline">
                    <input type="text" name="cType" autocomplete="off" class="layui-input" id="cType" readonly />
                    <input type="text" name="parentCode" autocomplete="off" class="layui-input" id="parentCode" readonly />
                </div>

            </div>
            <input type="hidden" name="id" id="id">
        </form>

    </div>
</body>
</html>

<script>
    var gvalue = "",fvalue="";
    var dataId = "";
    $(function () {
        gvalue = getUrlVariable("gvalue");
        fvalue = getUrlVariable("fvalue");
        dataId = getUrlVariable("dataId");
        $("input[ name='parentCode']").val(gvalue);
        if (fvalue != "") {
            $("input[ name='cType']").val(fvalue);
            $("#parentCode").css({ "display": "none" });
        } else {
            $("input[ name='parentCode']").val(gvalue);
            $("#cType").css({ "display": "none" });
           
        }
        if (dataId != "0") {
            $("#cCode").attr("disabled", "disabled");
            $("input[ name='id']").val(dataId);
            loadData();
        } else {
            $("input[ name='cType']").val(fvalue);
        }
        layui.use('form', function () {
            var form = layui.form;
            form.render();
        });
        FetchParents();
    })

    //加载数据信息
    function loadData() {
        $.ajax({
            url: "../Basis/getCommonDataById",
            type: "post",
            data: { dataId: dataId },
            async: false,
            success: function (data) {
                if (data.Result) {
                    //var json = JSON.parse(data.Data[0]["gxContents"]);
                    $.each(data.Data[0], function (name, value) {
                        $("input[ name='" + name + "']").val(value);
                    });
                }
            }
        });
    }
    function saveData() {
        layui.use("layer", function () {
            $.ajax({
                url: "../Basis/UpdateCommonData",
                data: { datas: JSON.stringify(FormToJson("AddForm")) },
                dataType: "json",
                type: "POST",
                success: function (data) {
                    if (data.Result) {
                        var id = $("input[ name='id']").val();
                        var msg = "信息修改成功";
                        if (id == "0" || id == "") {
                            msg = "信息添加成功";
                        }
                        layer.alert(msg, { icon: 6 }, function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                    } else {
                        layer.msg(data.Message);
                    }
                }
            });
        })
        
    }

    function FetchParents() {
        $.ajax({
            url: "../Basis/getParentCodes",
            dataType: "json",
            type: "POST",
            async: false,
            success: function (data) {
                if (data.Result) {
                    var datas = data.Data;
                    for (var i = 0; i < datas.length; i++) {
                        $(".pClass").append("<option value=\"" + datas[i]["cType"] + "\" >" + datas[i]["cName"] + "</option>");
                    }

                }
            }
        });
    }
</script>